/*
 * Created by Spear (http://www.codernet.es), spear@codernet.es
 * Coordinator of XNA Community (http://www.codeplex.com/XNACommunity)
 * 
 */
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace XMas
{
    /// <summary>
    /// Class to read skeleton data content
    /// </summary>
    /// <remarks>
    /// Stolen from Spear (http://www.codernet.es), spear@codernet.es
    /// Coordinator of XNA Community (http://www.codeplex.com/XNACommunity)
    /// </remarks>
    public class CSkeletonDataReader : ContentTypeReader<CSkeletonData>
    {
        /// <summary>
        /// Read the skeleton data from content
        /// </summary>
        /// <param name="input">ContectRead to read skeleton</param>
        /// <param name="existingInstance"></param>
        /// <returns>Skeleton data readed</returns>
        protected override CSkeletonData Read(ContentReader input, CSkeletonData existingInstance)
        {
            CSkeletonData skeleton_data = new CSkeletonData();
            skeleton_data.list_animations = input.ReadObject<Dictionary<string, CSkeletonData.CAnimationData>>();
            skeleton_data.worldModelTransform = input.ReadObject<Matrix>();
            skeleton_data.bind_skeleton = input.ReadObject<List<Matrix>>();
            skeleton_data.inverse_bind_skeleton = input.ReadObject<List<Matrix>>();
            skeleton_data.tangents = input.ReadObject<List<Vector3>>();
            skeleton_data.binormals = input.ReadObject<List<Vector3>>();
            skeleton_data.normals = input.ReadObject<List<Vector3>>();
            return skeleton_data;
        }
    }

    /// <summary>
    /// Class to read animation data from content
    /// </summary>
    /// <remarks>
    /// Stolen from Spear (http://www.codernet.es), spear@codernet.es
    /// Coordinator of XNA Community (http://www.codeplex.com/XNACommunity)
    /// </remarks>
    public class CAnimationDataReader : ContentTypeReader<CSkeletonData.CAnimationData>
    {
        /// <summary>
        /// Read the animation data from content
        /// </summary>
        /// <param name="input">ContectRead to read animation</param>
        /// <param name="existingInstance"></param>
        /// <returns>Animation data readed</returns>
        protected override CSkeletonData.CAnimationData Read(ContentReader input,
                                          CSkeletonData.CAnimationData existingInstance)
        {
            CSkeletonData.CAnimationData animation_data = new CSkeletonData.CAnimationData();
            animation_data.frame_rate = input.ReadObject<float>();
            animation_data.list_frames = input.ReadObject<List<CSkeletonData.CFramesData>>();
            return animation_data;
        }
    }

    /// <summary>
    /// Class to read frames data from content
    /// </summary>
    /// <remarks>
    /// Stolen from Spear (http://www.codernet.es), spear@codernet.es
    /// Coordinator of XNA Community (http://www.codeplex.com/XNACommunity)
    /// </remarks>
    public class CFramesDataReader : ContentTypeReader<CSkeletonData.CFramesData>
    {
        /// <summary>
        /// Read the frames data from content
        /// </summary>
        /// <param name="input">ContectRead to read animation</param>
        /// <param name="existingInstance"></param>
        /// <returns>Frames data readed</returns>
        protected override CSkeletonData.CFramesData Read(ContentReader input,
                                          CSkeletonData.CFramesData existingInstance)
        {
            CSkeletonData.CFramesData frames_data = new CSkeletonData.CFramesData();
            frames_data.list_skeleton = input.ReadObject<List<CSkeletonData.CSkeletonNode>>();
            return frames_data;
        }
    }

    /// <summary>
    /// Class to read node data from content
    /// </summary>
    /// <remarks>
    /// Stolen from Spear (http://www.codernet.es), spear@codernet.es
    /// Coordinator of XNA Community (http://www.codeplex.com/XNACommunity)
    /// </remarks>
    public class CSkeletonNodeReader : ContentTypeReader<CSkeletonData.CSkeletonNode>
    {
        /// <summary>
        /// Read the node data from content
        /// </summary>
        /// <param name="input">ContectRead to read animation</param>
        /// <param name="existingInstance"></param>
        /// <returns>Node data readed</returns>
        protected override CSkeletonData.CSkeletonNode Read(ContentReader input,
                                     CSkeletonData.CSkeletonNode existingInstance)
        {
            CSkeletonData.CSkeletonNode node = new CSkeletonData.CSkeletonNode();
            node.pos = input.ReadObject<Vector3>();
            node.oriented = input.ReadObject<Quaternion>();
            node.parent = input.ReadObject<int>();
            return node;
        }
    }
}
